(define iter&index
  (lambda (f L)
    (let ((n (length L)))
      (let loop ((res '())
                 (i 0)
                 (xs L))
        (if (null? xs)
            res
            (loop (append res (list (f i (car xs))))
                  (+ 1 i)
                  (cdr xs)))))))

;;(iter&index (lambda (i x) (+ i x)) '(1 2 3))

(define iter-by-ij
  (lambda (LL)
    (lambda (f)
      (iter&index
       (lambda (i L)
         (iter&index
          (lambda (j x)
            (f i j x))
          L))
       LL))))


((iter-by-ij
  '((0 0 0)
    (0 0 0)
    (0 0 0)))
 (lambda (i j x)
   (list i j)))




(define sub-matrix
  (lambda (M)
    (lambda (i0 j0 i1 j1)
      (lambda (k)
        (k )
        )
      )))


(define sub-matrix-map
  (lambda (M)
    (lambda (i0 j0 i1 j1)
      (lambda (k)
        ((iter-by-ij M)
         (lambda (i j x)
           (if (and (<= i0 i i1)
                    (<= j0 j j1))
               (k (- i i0) (- j j0) x)
               x)))
        )
      )))

(pretty-print
 (((sub-matrix-map
    '((0 0 0 0)
      (1 1 0 0)
      (0 1 1 0)
      (0 0 0 0)))
   1 1 2 2)
  (lambda (i j x)
    #f)
  ))

(let ()
  (define f
    (lambda (L)
      (if (null? L)
          0.0
          (+ (car L)
             (/ 1.0
                (f (cdr L)))))))
  (f '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16)))

(let ((LL '((1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)
            (1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2)
            (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16))))
  (define f
    (lambda (L)
      (if (null? L)
          0.0
          (+ (car L)
             (/ 1.0
                (f (cdr L)))))))
  (define f-reverse
    (lambda (x)
      (define =
        (lambda (x y)
          (<= (abs (- x y)) 0.001)))
      (let* ((a (floor x))
             (x* (- x a)))
        (cond ((= x* 0) (list a))
              (else
               (cons a (f-reverse (/ 1.0 x*))))))))
  (trace f-reverse)
  (f-reverse (expt 2 0.5))
  (map f LL)
  )



